package org.example.hansp.collection_.exercise;

import java.util.ArrayList;
import java.util.Collections;

@SuppressWarnings({"all"})
public class HomeWork01 {
    public static void main(String[] args) {
        newPage page1 = new newPage("新冠确诊病例超过千万，数百万印度教信徒赴恒河“圣浴”引民众担忧");
        newPage page2 = new newPage("男子突然想起2个月前钓的鱼还在网兜里，捞起一看赶紧放生");
        ArrayList list = new ArrayList();
        list.add(page1);
        list.add(page2);
        Collections.reverse(list);
        for (Object o : list) {
            newPage page = (newPage) o;
            /*if (page.getTitle().length() >= 15) {
                System.out.println(page.getTitle().substring(0, 15) + "...");
            } else {
                System.out.println(page);
            }*/
            System.out.println(page.processTitle(page.getTitle()));
        }
    }
}

class newPage {
    private String title;
    private String content;

    public newPage(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "newPage{" +
                "title='" + title + '\'' + "}"
                ;
    }
    public String processTitle(String title) {
        if(title==null || title.isEmpty()){
            return "";
        }
        if(title.length() >= 15) {
            return title.substring(0, 15) + "...";
        }else{
            return title;
        }
    }
}